package com.fdd.op.sdk.request.api.contract.sign;

import com.fdd.op.sdk.ApiRuleException;
import com.fdd.op.sdk.BaseFddRequest;
import com.fdd.op.sdk.constants.Constants;
import com.fdd.op.sdk.internal.mapping.RequestField;
import com.fdd.op.sdk.internal.util.StringUtils;
import com.fdd.op.sdk.model.dto.PushSignInfoDTO;
import com.fdd.op.sdk.response.api.contract.sign.PushResponse;

import java.util.List;
import java.util.Map;

public class PushRequest extends BaseFddRequest<PushResponse> {
    @Override
    public String getApiMethodName() {
        return "/base/api/contract/sign/push";
    }

    @Override
    public Map<String, Object> getTextParams() {
        return null;
    }

    @Override
    public Class<PushResponse> getResponseClass() {
        return PushResponse.class;
    }

    @Override
    public void check() throws ApiRuleException {
        if(getSignerInfos() == null || getSignerInfos().size() == 0){
            throw new ApiRuleException("2", "参数验证失败，signerInfos不能为空");
        }
        for (PushSignInfoDTO signerInfo : getSignerInfos()) {
            if(StringUtils.isBlank(signerInfo.getNotifyNo())){
                throw new ApiRuleException("2", "参数验证失败，notifyNo不能为空");
            }
        }
        if(StringUtils.isBlank(getDocId()) && StringUtils.isBlank(getTpDocId())){
            throw new ApiRuleException("33030", "文档在在电子签系统的docId与在客户业务系统的tpDocId不允许同时为空！");
        }
    }

    @Override
    public String getHttpMethod() {
        return Constants.METHOD_POST;
    }

    @RequestField
    private String docId;

    @RequestField
    private String tpDocId;

    @RequestField
    private Integer isAutoArchive;

    @RequestField
    private List<PushSignInfoDTO> signerInfos;

    public String getDocId() {
        return docId;
    }

    public void setDocId(String docId) {
        this.docId = docId;
    }

    public String getTpDocId() {
        return tpDocId;
    }

    public void setTpDocId(String tpDocId) {
        this.tpDocId = tpDocId;
    }

    public Integer getIsAutoArchive() {
        return isAutoArchive;
    }

    public void setIsAutoArchive(Integer isAutoArchive) {
        this.isAutoArchive = isAutoArchive;
    }

    public List<PushSignInfoDTO> getSignerInfos() {
        return signerInfos;
    }

    public void setSignerInfos(List<PushSignInfoDTO> signerInfos) {
        this.signerInfos = signerInfos;
    }
}
